require "test/unit"
class Test_Koans<Test::Unit::TestCase

  def test_everything_is_an_object
    assert_equal true, 1.is_a?(Object)
    assert_equal true, 1.5.is_a?(Object)
    assert_equal true, "string".is_a?(Object)
    assert_equal true, nil.is_a?(Object)
    assert_equal true, Object.is_a?(Object) 
  end
  #  在ruby中所有的东西都是对象，数字，符号，字符串，nil，全都是对象

  def test_objects_can_be_converted_to_strings
    assert_equal "123", 123.to_s   #将123转换为字符串显示
    assert_equal "", nil.to_s  #将nil以字符串形式显示
  end

  def test_objects_can_be_inspected
    assert_equal "123", 123.inspect
    assert_equal "nil", nil.inspect   #.inspect与.to_s的区别，都是转换为字符串，但to_s是以值的形式显示，inspect只将内容显示
  end

  def test_every_object_has_an_id
    obj = Object.new
    assert_equal Fixnum, obj.object_id.class 
  end              
  #每个对象都有一个id，id属于Fixnum这个类

  def test_every_object_has_different_id
    obj = Object.new
    another_obj = Object.new
    assert_equal true, obj.object_id != another_obj.object_id 
  end
  #每个对象都有一个单独的object_id

  def test_some_system_objects_always_have_the_same_id
    assert_equal 0, false.object_id
    assert_equal 2, true.object_id
    assert_equal 4, nil.object_id
  end
  #每个对象都有一个单独的object_id， 但一些系统对拥有相同的固定的object_id

  def test_small_integers_have_fixed_ids
    assert_equal 1, 0.object_id
    assert_equal 3, 1.object_id
    assert_equal 5, 2.object_id
    assert_equal 201, 100.object_id
  end
  #数字的object_id往往是它们的双倍加1

  def test_clone_creates_a_different_object
    obj = Object.new
    copy = obj.clone
    assert_equal true, obj != copy
    assert_equal true, obj.object_id != copy.object_id  
  end
  #将一个文件复制，但两个文件并不一样，因为拥有不同的object_id
end

